<?php

use think\migration\Migrator;
use think\migration\db\Column;

class SupplierDividend extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $this->table('supplier_dividend', ['comment' => '经销商分红表利率表'])
             ->addColumn('company_id', 'integer', ['limit' => 11, 'default' => 0, "after" => 'id', 'comment' => '公司ID'])
             ->addColumn('supplier_id', 'integer', ['limit' => 11, 'default' => 0, "after" => 'company_id', 'comment' => '经销商ID'])
             ->addColumn('investor_id', 'integer', ['limit' => 11, 'default' => 0, "after" => 'company_id', 'comment' => '招商人ID(supplier_user表Id)'])
             ->addColumn('investor_ratio', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, "after" => 'investor_id', 'comment' => '招商人分红比例'])
             ->addColumn('service_id', 'integer', ['limit' => 11, 'default' => 0, "after" => 'investor_ratio', 'comment' => '服务人ID(supplier_user表Id)'])
             ->addColumn('service_ratio', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, "after" => 'service_id', 'comment' => '服务人分红比例'])
             ->addColumn('department_ratio', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 10.00, "after" => 'service_ratio', 'comment' => '职能部门分红比例'])
             ->addColumn('partner_ratio', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 100.00, "after" => 'department_ratio', 'comment' => '合伙人(经销商)分红比例'])
             ->addColumn('partner_id', 'integer', ['limit' => 10, 'after' => 'partner_ratio', 'default' => 1, 'comment' => '合伙人(经销商)'])
             ->addColumn('status', 'integer', ['limit' => 1, 'default' => 1, 'after' => 'partner_id', 'comment' => '1:正常,2:禁用'])
             ->addColumn('create_time', 'integer', ['limit' => 10, 'after' => 'status', 'default' => 0, 'comment' => '创建时间'])
             ->addColumn('update_time', 'integer', ['limit' => 10, 'after' => 'create_time', 'default' => 0, 'comment' => '更新时间'])
             ->addColumn('delete_time', 'integer', ['limit' => 10, 'after' => 'update_time', 'default' => 0, 'comment' => '删除时间'])
             ->addIndex('company_id', ['name' => 'company_id'])
             ->addIndex('supplier_id', ['name' => 'supplier_id'])
             ->create();

        $this->table('partner_dividend', ['comment' => '公司分红设置表'])
             ->addColumn('date', 'date', ['limit' => 11, 'default' => 0, "after" => 'id', 'comment' => '日期'])
             ->addColumn('turnover', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0.00, "after" => 'date', 'comment' => '营业额'])
             ->addColumn('cost', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0.00, "after" => 'turnover', 'comment' => '成本'])
             ->addColumn('dividend_ratio', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0.00, "after" => 'cost', 'comment' => '分红比例'])
             ->addColumn('money', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0.00, "after" => 'dividend_ratio', 'comment' => '分红金额(基数金额)'])
             ->addColumn('dividend_status', 'integer', ['limit' => 1, 'default' => 1, 'after' => 'money', 'comment' => '是否分红 1:未分红,2:已分红'])
             ->addColumn('status', 'integer', ['limit' => 1, 'default' => 1, 'after' => 'money', 'comment' => '1:正常,2:禁用'])
             ->addColumn('create_time', 'integer', ['limit' => 10, 'after' => 'status', 'default' => 0, 'comment' => '创建时间'])
             ->addColumn('update_time', 'integer', ['limit' => 10, 'after' => 'create_time', 'default' => 0, 'comment' => '更新时间'])
             ->addColumn('delete_time', 'integer', ['limit' => 10, 'after' => 'update_time', 'default' => 0, 'comment' => '删除时间'])
             ->create();

        $this->table('company_user_dividend', ['comment' => '公司员工分红表'])
             ->addColumn('company_id', 'integer', ['limit' => 10, 'default' => 0, 'comment' => '公司id'])
             ->addColumn('company_user_id', 'integer', ['limit' => 10, 'default' => 0, 'comment' => '公司员工id'])
             ->addColumn('turnover', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0.00, "after" => 'date', 'comment' => '营业额'])
             ->addColumn('cost', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0.00, "after" => 'turnover', 'comment' => '成本'])
             ->addColumn('dividend_ratio', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0.00, "after" => 'cost', 'comment' => '分红比例'])
             ->addColumn('money', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0.00, "after" => 'dividend_ratio', 'comment' => '分红基数(基数金额)'])
             ->addColumn('amount', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0.00, "after" => 'money', 'comment' => '分红金额'])
             ->addColumn('status', 'integer', ['limit' => 1, 'default' => 1, 'after' => 'amount', 'comment' => '1:正常,2:禁用'])
             ->addColumn('create_time', 'integer', ['limit' => 10, 'after' => 'status', 'default' => 0, 'comment' => '创建时间'])
             ->addColumn('update_time', 'integer', ['limit' => 10, 'after' => 'create_time', 'default' => 0, 'comment' => '更新时间'])
             ->addColumn('delete_time', 'integer', ['limit' => 10, 'after' => 'update_time', 'default' => 0, 'comment' => '删除时间'])
             ->addIndex('company_id', ['name' => 'company_id'])
             ->addIndex('company_user_id', ['name' => 'company_user_id'])
             ->create();
    }
}
